let promise1 = new Promise((resolve, reject) => {
    setTimeout(() => {
        resolve('result')
    }, Math.random()*3000)
})

let timeReject = (promise1, timeout = 2000) => {
    let promise2 = new Promise((resolve, reject) => {
        setTimeout(() => {
            reject('网络超时')
        }, timeout)
    })
    return  Promise.race([promise1, promise2])
}

timeReject(promise1).then((result) => {
    console.log(result);
}).catch((err) => {
    console.log(err);
});

